# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)

platform :ios do
  ipaFullName = "好汽修.ipa"

  lane :toPgyer do
    doCocoapod # pod install 
    doIncrementBuildNumber # build + 1
    build_app(scheme: "HQXDDQP",
      workspace: "HQXDDQP.xcworkspace",
      export_method: "ad-hoc", 
      output_directory: '../打包文件',
      output_name: ipaFullName
    ) #App ad-hoc 包
    pgyer(api_key: "3730631c0cc12f0a83aefe9b96f2850e", user_key: "6da668176f288e152954d7aa9b4d5171" , password: "QWE123") #上传蒲公英
    gitPush
  end

  lane :toTestFlight do
    doCocoapod # pod install
    build_app(
      scheme: "HQXDDQP", 
      workspace: "HQXDDQP.xcworkspace",
      output_directory: '../打包文件',
      output_name: ipaFullName,
      export_method: "app-store") # app-store包
    doPilot # 上传到AppStore
  end


end

private_lane :doCocoapod do
  cocoapods # pod install
end


private_lane :doPilot do 
  api_key = app_store_connect_api_key(
    key_id: "7VP434FJA4",
    issuer_id: "069d2bc5-a893-46a7-b826-52770ab30a28",
    key_filepath: "./fastlane/AuthKey_7VP434FJA4.p8",
    duration: 1200, # optional (maximum 1200)
    in_house: false # optional but may be required if using match/sigh
  )
  pilot(api_key: api_key, ipa: "../打包文件/#{ipaFullName}", skip_waiting_for_build_processing: true)
end

private_lane :doIncrementBuildNumber do
  increment_build_number
end

private_lane :gitPush do 
  git_pull
  doCocoapod
  git_add(path: ".")
  git_commit(path: ".", message: "修改build号")
  push_to_git_remote
end

